<?php
namespace plugin\luyouzujiditu\api;

use think\facade\Db;
use plugin\luyouzujiditu\common\Common;
use plugin\luyouzujiditu\validate\SettingsValidate as validates ;
use Naux\AutoCorrect;
use app\banmi\common\Basehome;

 

 
class Settings extends Basehome
{
    public $NotLogin=["index","top","map"];
 
    /**
     *  获取基本设置信息
     * @param index
     * @param
     */
    public function index()
    {
        $data['set_find']= plugin_config(0);
		$currentFilePath = dirname(__FILE__);
			 
		$jsonString = file_get_contents($currentFilePath.'/100000_full.json');
		$json = json_decode($jsonString, true);
		$data['json']= $json;
        ajaxmsg('ok', 200, $data,false);
    }
 
    public function top()
    {
        $shi=input('request.shi', 0);
        $find = Db::name('plugin_luyouzujiditu_top')->where('num', $shi)->find();
        $url= home_url()."h5/luyouzujiditu/";
        if ($find) {
            $proportion = $find["proportion"];
            $data['proportion']= $proportion;
            $data['name']= $find["name"];
            $data['url']= $url;
            $data['haibao']= $this->img($find["name"], $proportion);
            ajaxmsg('ok', 200, $data,false);
        }
        $map[] =["max_num",">=" , $shi];
        $find = Db::name('plugin_luyouzujiditu_top')->where($map)->order('min_num', 'asc')->find();
        if ($find) {
            $proportion = $find["proportion"];
            $data['proportion']= $proportion;
            $data['name']= $find["name"];
            $data['url']= $url;
            $data['haibao']= $this->img($find["name"], $proportion);
            ajaxmsg('ok', 200, $data,false);
        }
        $data['proportion']= 0;
        $data['url']= $url;
        $data['name']= "未检测到排名";
		$data['haibao']= $this->img("未检测到排名", 0);
        ajaxmsg('ok', 200, $data,false);
    }
    
    public function img($name, $proportion)
    {
        
        
        $sheng=input('request.sheng', 0);
        $shi=input('request.shi', 0);
        
        $content1="我走过 ".$sheng." 个省， ".$shi." 个城市";
        $content2=$proportion."%";
        
        $ma_f =root_path()."bmapp/attachment/luyouzujiditu.jpg";
     
         if (!file_exists($ma_f)) {
          
              $this->qrCode();
         }  
        
        
        $bj_file ="plugin/luyouzujiditu/view/plugin_static/images/22.jpg";
        $ma_file ="attachment/luyouzujiditu.jpg";
        $ma= home_url().$ma_file;
        $bj= home_url().$bj_file;
        $banmi_platform=input('request.banmi_platform', 0);
        if($banmi_platform=="H5"){
           $ma_file_g = file_get_contents(root_path().'bmapp/'.$ma_file); 
           $ma="data:image/jpg;base64," .base64_encode($ma_file_g);
           $bj_file_g = file_get_contents(root_path().$bj_file); 
           $bj="data:image/jpg;base64," .base64_encode($bj_file_g);
        }
      
        
       
       
        $list= [
          [
            "type"=>'image',
			"content"=> $bj,
			"width"=> 500,
			"height"=> 800,
			"x" => 0,
			"y"=> 0,
          ],
          [
          "type"=>"text",
          "content"=>$name,
          "x"=> 250 ,
          "y"=>63,
          "color"=>"#FFFF00",
          "size"=>28,
           "align"=>"center",
          ],
        [
         "type"=>"text",
         "content"=> $content1,
         "x"=> 250 ,
         "y"=>100,
         "color"=>"#fff",
         "size"=>18,
         "align"=>"center",
         ],
        [
          "type"=>"text",
           "content"=>"超越了                      的用户",
           "x"=>250,
           "y"=>135,
           "color"=>"#fff",
           "size"=>18,
           "align"=>"center",
          ],
        
         [
            "type"    => "text",
            "content" => $content2,
            "x"       =>  250  ,
            "y"       =>  140,
            "color"   => '#FFFF00',
            "size"    => 30,
            "align"=>"center",
          ],
          [
					"type" =>'image',
					"content" => $ma,
					"width" => 80,
					"height" => 80,
					"x" => 0,
					"y"=> 600,
					"align" => "center",
					"c_width" => 500
				],
        // [
        //     "type"=>"text",
        //     "content"=>"",
        //     "x"=>220,
        //     "y"=>675,
        //     "color"=>"#fff",
        //      "size"=>18,
        //       "align"=>"center",
        //     ]
     ];
     
        return $list;
    }
     public function qrCode()
    {
 
 
      
    
       require  root_path()."plugin/luyouzujiditu/vendor/phpqrcode/phpqrcode.php";
       $qRcode = new \QRcode();
       $data = home_url().'h5/luyouzujiditu/';
    
       //网址或者是文本内容
       // 纠错级别：L、M、Q、H
       $level = 'L';
       // 点的大小：1到10,用于手机端4就可以了
       $size = 4;
       // 生成的文件名
       $outfile = root_path() . "bmapp/attachment/luyouzujiditu.jpg"; 
       $qRcode->png($data, $outfile, $level, $size);
    //   $imagestring = base64_encode(ob_get_contents());
  
   

}
  // 生成二维码  
     
      
}
